package main

import (
	common "CRM_rorm/logic"
	"CRM_rorm/route"
	"CRM_rorm/service"
	"fmt"
	"github.com/gin-gonic/gin"
	"github.com/spf13/viper"
	"os"
)

func main() {
	InitConfig()
	service.NewServiceContext(common.InitDB())
	port := viper.GetString("server.port")
	fmt.Println(port)
	r := gin.Default()
	fmt.Println(r)
	r = route.CollectRoute(r)
	if port != "" {
		r.Run(":" + port)
	} else {
		r.Run() //默认端口号：8080
	}
}
func InitConfig() {
	workDir, _ := os.Getwd()      //获取目录对应的路径
	viper.SetConfigName("config") //配置文件名
	viper.SetConfigType("yml")    //配置文件类型
	//viper.AddConfigPath(workDir + "config") //执行go run对应的路径配置
	viper.AddConfigPath(workDir + "/config") //执行单文件运行，
	fmt.Println(workDir)
	err := viper.ReadInConfig()
	if err != nil {
		panic(err)
	}

}
